const ble = require('../../utils/ble');

Page({
  data: {
    devices: []
  },

  async onLoad() {
    try {
      await ble.init();
    } catch (e) {
      wx.showToast({ title: '请开启蓝牙', icon: 'none' });
    }
  },

  onShow() {
    // 这里可从本地缓存加载已绑定设备列表（示例为空）
  },

  goAdd() {
    console.log('goAdd 被点击');
    wx.navigateTo({ 
      url: '/pages/provision/bind/bind',
      success: () => {
        console.log('跳转成功');
      },
      fail: (err) => {
        console.error('跳转失败:', err);
        wx.showToast({ title: '跳转失败', icon: 'none' });
      }
    });
  },

  onOpen(e) {
    const { id, name } = e.currentTarget.dataset;
    wx.navigateTo({ url: `/pages/device/device?name=${encodeURIComponent(name)}&id=${encodeURIComponent(id)}` });
  }
});


